package com.dqy.twserver.server.handle.ehandle;

import com.dqy.twserver.server.GameServer;
import com.dqy.twserver.server.dto.GameDto;
import com.dqy.twserver.server.support.SupportMap;
import com.dqy.twserver.server.support.data.RoomInfo;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class GameEventGetRoomHandle implements  GameEventHandle{
    static Logger logger = LoggerFactory.getLogger(GameEventGetRoomHandle.class);

    @Override
    public void handle(GameDto req, NioSocketChannel channel) throws Exception {
        logger.info("[GameEventGetRoomHandle] start");
        Map<Integer, RoomInfo> roomMap = SupportMap.roomMap;
        GameDto resp=new GameDto();
        String roomListStr="";
        if(roomMap.keySet().size()==0){
            logger.info("[GameEventGetRoomHandle] 没有房间");
        }else {
            for (Integer id : roomMap.keySet()) {
                RoomInfo roomInfo = roomMap.get(id);
                roomListStr += roomInfo.toString();
                roomListStr += "-";
            }
            roomListStr=roomListStr.substring(0,roomListStr.length()-1);
            logger.info("[GameEventGetRoomHandle] 房间信息{}",roomListStr);
        }
        resp.setRoomListStr(roomListStr);
        resp.setSts(200);
        channel.writeAndFlush(resp);
        logger.info("[GameEventGetRoomHandle] end");
    }
}
